package design_mode.singleton;

/**
 * Created mangcao with 2019/5/31 11:11
 * Description: 懒汉模式 单例
 */
public class LazySingletonV2
{
    // 指令重排序
    private static volatile LazySingletonV2 lazySingleton;

    private LazySingletonV2(){}

    //双重校验锁
    public static LazySingletonV2 getInstance() {
        if (lazySingleton == null) {
            synchronized (LazySingletonV2.class) {
                //多线程并发
                if (lazySingleton == null) {
                    lazySingleton = new LazySingletonV2();
                }
            }
        }
        return lazySingleton;
    }

}
